#include "Gold.h"
#include "config.h"

Gold::Gold(b2World * pW, const CCPoint & p)
: Prop(pW)
, pos(p)
{
}

Gold::~Gold()
{
}

void Gold::createBody()
{
  b2BodyDef groundBodyDef;
  groundBodyDef.position.Set(pos.x, pos.y);

  m_pB2Body = pWorld->CreateBody(&groundBodyDef);

  b2PolygonShape groundBox;

  groundBox.SetAsBox(0.5, 0.5);
  m_pB2Body->CreateFixture(&groundBox, 0);

  m_pB2Body->SetUserData((GameEntity *)this);
}

PropType Gold::getPropType()
{
  return GOLD;
}

bool Gold::init()
{
  do
  {
    createBody();
    setPTMRatio(PTM_RATIO);
    initWithSpriteFrame(CCSpriteFrameCache::sharedSpriteFrameCache()->spriteFrameByName("tortoise.png"));
    return true;
  } while (0);
  return false;
}

Gold * Gold::create(b2World * pWorld, const CCPoint & pos)
{
  Gold * pGold = new Gold(pWorld, pos);
  if (pGold && pGold->init())
  {
    pGold->autorelease();
    return pGold;
  }
  else
  {
    CC_SAFE_DELETE(pGold);
    return NULL;
  }
}
